package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 12/22/20 10:22 AM
 *
 * https://leetcode-cn.com/problems/move-zeroes/
 */
public class _283_移动零_01 {

    public void moveZeroes(int[] nums) {

        if (nums == null || nums.length == 0) {

            return;
        }


        /**
         * nums[i] 不等于0时， left i 一起向前走，当遇到 nums[i] 为0时，i往前走
         */
        int left = 0;
        for (int i = 0; i < nums.length; i++) {

            if (nums[i] != 0) {

                if (left != i) {

                    nums[left] = nums[i];
                    nums[i] = 0;
                }

                left++;
            }
        }

    }
}
